package com.atguigu.day03;

import com.atguigu.utils.IntSource;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Example1 {
    public static void main(String[] args) throws Exception{
        //获取上下文
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        //设置并行度
        env.setParallelism(1);

        //读取数据
        DataStreamSource<Integer> source = env.addSource(new IntSource());

        //匿名函数方式 累加求和
        source
                .keyBy(r -> true)
                .sum(0)
                .print("sum value: ");

//        //匿名函数方式写全了
//        source
//                .keyBy(new KeySelector<Integer, Boolean>() {
//                    @Override
//                    public Boolean getKey(Integer integer) throws Exception {
//                        return true;
//                    }
//                }).sum(0).print();

        //求最大值
        source
                .keyBy(r -> true)
                .max(0)
                .print("max value: ");



        //执行任务
        env.execute();
    }


}
